package com.example.demo.controller;

import com.example.comon.domain.LoginUser;
import com.example.comon.domain.R;
import com.example.comon.utils.UserUtil;
import com.example.demo.domain.Bo.AddLeaveBo;
import com.example.demo.domain.Bo.LeaveListBo;
import com.example.demo.domain.Leave;
import com.example.demo.domain.Vo.LeaveVo;
import com.example.demo.service.ILeaveService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/leaveApplication")
@Api(value = "leaveApplication",tags = "请假申请控制器")
public class LeaveApplicationController {

    @Autowired
    private ILeaveService leaveService;


    @GetMapping("/getLeaveList")
    @ApiOperation("获取请假申请列表")
    public R<List<LeaveVo>> getLeaveList(LeaveListBo bo){
        Leave leave = new Leave();
        leave.setLeaveId(bo.getEmployeeId());
        List<LeaveVo>list = leaveService.selectLeave(leave);
        return R.success(list);
    }

    @PostMapping("/addLeave")
    @ApiOperation("增加请假申请")

    public R<Leave> addLeave(@RequestBody AddLeaveBo bo){
        Leave leave = new Leave();
        leave.setEmployeeId(bo.getEmployeeId());
        leave.setLeaveType(bo.getLeaveType());
        leave.setLeaveStartTime(bo.getLeaveStartTime());
        leave.setLeaveEndTime(bo.getLeaveEndTime());
        leave.setLeaveReason(bo.getLeaveReason());
        leave.setLeaveTime(bo.getLeaveTime());
        leaveService.insertLeave(leave);
        return R.success(leave);
    }

    @PostMapping("/updateLeaveById")
    @ApiOperation("修改请假申请")
    public R updateLeaveById(@RequestBody Leave leave) {
        leaveService.updateLeaveById(leave);
        return R.success();
    }

    @DeleteMapping("/delLeaveById")
    @ApiOperation("删除请假申请")
    public R delLeaveById(long leaveId){
        leaveService.delLeaveById(leaveId);
        return R.success();
    }

}
